import os


class Data_utils(object):

    def __init__(self):
        pass

    @classmethod
    def ClearData(cls):
        root_path = os.path.join(os.getcwd(), "..")
        path =root_path + "/data/horse_colic"

        # 训练接的数据清洗
        train = []
        with open(os.path.join(path, "horse-colic.data")) as file:
            data = file.readlines()
        for item in data:
            item = item.split()
            if item[-1] == "2":
                clas = "0"
            else:
                clas = item[-1]
            item = item[:2] + item[3:-6]
            item.append(clas)
            item = ["0" if i == "?" else i for i in item]
            item = " ".join(item)
            train.append(item)

        # 验证集的数据清洗
        test = []
        with open(os.path.join(path, "horse-colic.test")) as file:
            data = file.readlines()
        for item in data:
            item = item.split()
            if item[-1] == "2":
                clas = "0"
            else:
                clas = item[-1]
            item = item[:2] + item[3:-6]
            item.append(clas)
            item = ["0" if i == "?" else i for i in item]
            item = " ".join(item)
            test.append(item)

        file = open(root_path + "/data/test.txt", "w")
        for line in test:
            file.write(line+"\n")
        file.close()




temp = Data_utils.ClearData()

